#include "ClassificationMenu.h"
#include "Utilities.h"
#include "PrintUtilities.h"
#include "User.h"
#include "League.h"
#include "LeagueManager.h"
#include "MenuManager.h"
#include "TeamManager.h"
#include "GamePrintUtils.h"

#include <algorithm>

ClassificationMenu::ClassificationMenu(MenuManager* const i_menuManager)
	: Menu(i_menuManager)
{
}

void ClassificationMenu::OnEnter()
{
	m_selection = 0;
}

void ClassificationMenu::Draw() const
{
	std::cout << Print::Title("CLASSIFICATION:");
	const LeagueVec& leagues = GetSP()->GetLeagueMgr().GetLeagues(true);
	for (size_t i = 0; i< leagues.size(); ++i)
	{
		const League& league = *leagues.at(i);
		std::cout << "LEAGUE " << league.GetName() << std::endl;
		PrintClassification(std::cout, league);
		std::cout << std::endl;
	}

	if (m_selection > 0 && m_selection <= static_cast<int>(GetSP()->GetLeagueMgr().GetNumOfTeams(false)))
	{
		const Team* theTeam = GetSP()->GetTeamMgr().GetTeamFromID(m_selection);
		if(theTeam)
			PrintTeam(std::cout, *theTeam);
	}

	std::cout << Print::Options(
						"1-" +
						Utilities::IntToString(GetSP()->GetLeagueMgr().GetNumOfTeams(false)) +
						") Select team.\n\n"
						"0) Return to previous menu'")
						<< " Selection: ";
}


bool ClassificationMenu::Input(const std::string& i_input)
{
	bool goodInput = true;

	size_t res = Utilities::StringToInt(i_input);

	if (res == 0)
		GetMM()->SetMenu(GetMM()->GetMainMenu());
	else if (res > 0 && res <= GetSP()->GetLeagueMgr().GetNumOfTeams(false))
		m_selection = res;
	else
		goodInput = false;

	return goodInput;
}